package com.xqyq.dao;

import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.xqyq.model.Prize;

@Repository
public class PrizeDao {
	@Autowired
	private SessionFactory sessionFactory;
	
	public int  addPrize(Prize prize){
		Session session = sessionFactory.getCurrentSession();
		return (Integer) session.save(prize);
	}
	
	public void deletePrize(int prize_id){
		Session session = sessionFactory.getCurrentSession();
		Query query1 = session.createQuery("update Sign s set s.prize=null where s.prize.prize_id=?");
		query1.setInteger(0, prize_id);
		query1.executeUpdate();
		Query query2 = session.createQuery("delete from Prize where prize_id=?");
		query2.setInteger(0, prize_id);
		query2.executeUpdate();
	}

	
}
